#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import os
import sys

size_map = {
    'k': 1024,
    'm': 1024 ** 2,
    'g': 1024 ** 3,
    't': 1024 ** 4,
}

def main(argv):
    filename = argv[1]
    size = argv[2]

    size = size.lower()
    for ch in size_map.keys():
        if size.endswith(ch):
            size = int(size.rstrip(ch))
            size *= size_map[ch]
            break

    size = int(size)

    print("output to {}, size: {}".format(filename, size))

    with open(filename, "wb") as f:
        f.write(os.urandom(size))

if __name__ == "__main__":
    if len(sys.argv) < 3:
        print("Usage: {} filename size[k/m/g/t]".format(os.path.basename(sys.argv[0])))
        os._exit(-1)

    main(sys.argv)

